package com.gmall.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitMQConfig_Delay2 {

    public static final String Exchange_Custom_Delay = "Exchange_Custom_Delay";

    public static final String Queue_Custom_Delay = "Queue_Custom_Delay";

    public static final String ROUTING_KEY_1 = "ROUTING_KEY_1";

    @Bean(Exchange_Custom_Delay)
    public Exchange exchange_Direct_1(){
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");

        return new CustomExchange(Exchange_Custom_Delay,
                "x-delayed-message",
                true, false,
                args);
    }

    @Bean(Queue_Custom_Delay)
    public Queue queue_Direct_1(){
        return QueueBuilder.durable(Queue_Custom_Delay).build();
    }

    /**
     *将Queue_Direct_1 绑定到交换机Exchange_direct  with
     * @param queue
     * @param exchange
     * @return
     */
    @Bean
    public Binding binding_delay2(
            @Qualifier(Queue_Custom_Delay) Queue queue,
            @Qualifier(Exchange_Custom_Delay) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY_1).noargs();
    }

}
